home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1989 / Aug 89 / X0070-Re ?Memory Manageme-Aug89 < prev    next >
Encoding:
Text File  |  1991-03-06  |  2.8 KB  |  79 lines  |  [TEXT/GEOL]

  1. Item    3592180                         16-Aug-89        19:15
  2.  
  3. From:   ALGER                           Alger, Jeff,VCA
  4.  
  5. To:     AU0008                          Kopfwerk EDV SW Entwicklung
  6.  
  7. cc:     MACAPP.TECH$                    MACAPP Tech
  8.  
  9. Sub:    Response to ?Memory Management
  10.  
  11. Tommi,
  12.  
  13. Maybe someone else knows of a better way to list the total sizes of objects
  14. from the debugger, but if you are willing to roll up your sleeves a bit, all of
  15. the information is readily available in UInspector.  The method
  16.  
  17.    FUNCTION TInspector.GetObjectList(classId: ObjClassID): TObjectList;
  18.  
  19. returns a TObjectList, which is a subclass of TList containing all objects of
  20. the given class.  In UObject you will find the global procedure
  21.  
  22.    PROCEDURE EachClassDo(PROCEDURE DoToClass(theClass: ObjClassID));
  23.  
  24. which iterates over all classes.  Finally, TObject now has a method which
  25. returns the actual size currently occupied by an object:
  26.  
  27.    FUNCTION TObject.GetInstanceSize: INTEGER;
  28.  
  29. In theory, (I haven't actually tried it) one can chain all of this together to
  30. report the number and collective size of objects by class.  The only problem is
  31. that TInspector and its associated classes are declared privately in
  32. UInspector, so you have to modify MacApp source (in UInspector) to do this.
  33. ugh.
  34.  
  35. The following, put into UInspector.inc1.p, shows how:
  36.  
  37. PROCEDURE EachObjectForClass (theClass: ObjClassID;
  38.                                    PROCEDURE DoToObject (anObject: TObject));
  39.        VAR theClassList: TObjectList;
  40.        BEGIN
  41.            IF pInspector <> NIL THEN
  42.                BEGIN
  43.                    theClassList := pInspector.GetObjectList (theClass);
  44.                    IF theClassList <> NIL THEN
  45.                        theClassList.Each (DoToObject);
  46.                END;
  47.        END;
  48.  
  49. FUNCTION ComputeSizeForClass (theClass: ObjClassID;
  50.                                    VAR howManyAreThere: LONGINT): LONGINT;
  51.     VAR totalSize: LONGINT;
  52.     PROCEDURE DoToObject (theObject: TObject);
  53.         BEGIN
  54.             totalSize := totalSize + theObject.GetInstanceSize;
  55.                howManyAreThere := howManyAreThere + 1;
  56.         END;
  57.     BEGIN
  58.         totalSize := 0;
  59.            howManyAreThere := 0;
  60.            EachObjectForClass (theClass, DoToObject);
  61.         ComputeSizeForClass := totalSize;
  62.     END;
  63.  
  64. Use EachClassDo to iterate over all classes, calling ComputeSizeForClass for
  65. each one.  Again, I haven't tested this beyond making sure it compiles; it's
  66. just an idea I've had kicking around for awhile.  If anyone tries it out, let
  67. me know how it works.
  68.  
  69. It seems to me that the object lists by class could and should be published in
  70. the interface to UInspector for uses such as this, but perhaps there are
  71. problems with that of which I am unaware.  As it is, they are tied to views of
  72. the inspector window: one view per class.
  73.  
  74. Hope this helps.
  75.  
  76. Jeff Alger
  77. Peat Marwick Main & Co.
  78.  
  79.